<?php
namespace app\common\model\collect;

use think\admin\Model;
use think\facade\Cache;

/**
 * OrderExpressModel
 * @Description 采集订单物流表模型
 * @package app\common\model\collect
 * @author wangqinghui
 * @date 2024-12-05 13:42
 */
class OrderExpressModel extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'collect_order_express';

    // 自动写入时间戳
    protected $autoWriteTimestamp = false;

    const STATUS_WATING    =  -1;// 待确认
    const STATUS_NO_CHECK  =  0; // 待签收
    const STATUS_YES_CHECK =  1; // 待入库
    const STATUS_IN_STORE  =  2; // 已入库
    const STATUS_NO_SEND   =  3; // 待发货
    const STATUS_HAS_SEND  =  4; // 已发货
    const STATUS_HAS_GET   =  5; // 已签收
    /**
     * 日志名称
     * @var string
     */
    protected $oplogName = '采集订单物流';

    /**
     * 日志类型
     * @var string
     */
    protected $oplogType = '采集订单物流管理';

    /**
     * 获取采集来源
     * @Description
     * @author wangqinghui
     * @date 2024-12-05 13:43
     * @return array
     */
    public static function from_arr() : array
    {
        return [0 => lang('未知'), 1 => '1688'];
    }

    public static function getStatus ()
    {
        return [
            self::STATUS_WATING    => lang('待确认'),//待确认
            self::STATUS_NO_CHECK  => lang('待签收'), //待签收
            self::STATUS_YES_CHECK => lang('待入库'), //待入库
            self::STATUS_IN_STORE  => lang('待集包'), //待集包
            self::STATUS_NO_SEND   => lang('待发货'), //待发货
            self::STATUS_HAS_SEND  => lang('已发货'), //已发货
            self::STATUS_HAS_GET   => lang('已签收'),//已签收
        ];
    }

    public static function createCombineNo()
    {
        $name = 'HX';
        $id = Cache::get($name);
        if (!$id) {
            Cache::set($name, 1, strtotime('23:59:59') - time());
            return $name.date("Ymd") . "1";
        }
        Cache::set($name, $id + 1, strtotime('23:59:59') - time());
        $id = $id + 1;
        return $name.date("Ymd") . $id;
    }


    public function express_goods ()
    {
        //
        return $this->hasMany(OrderExpressGoodsModel::class, 'order_express_id');
    }
}